﻿using System;
using System.Collections.Generic;
using IOCDemo.Containers;
using IOCDemo.Domain;
using IOCDemo.Interfaces;

namespace IOCDemo
{
    internal class Program
    {
        private static void Main()
        {
            TestBankingService(new UnityIOCContainer());
            TestBankingService(new AutofacIOCContainer());
            Console.ReadKey();
        }

        private static void TestBankingService(IIOCContainer iocContainer)
        {
            // Get a logger and write out the IOC container being used.
            var loggingService = iocContainer.Resolve<ILoggingService>();
            loggingService.Info(string.Format("===== Using the {0} IOC Container Implementation =====",
                                              iocContainer.GetType().Name));
            // Get banking service
            var bankingService = iocContainer.Resolve<IBankingService>();
            // Authenticate
            AuthToken authToken = bankingService.AuthenticateUser("johnSmith1970", "password");
            // Get user
            User user = bankingService.GetUser(authToken);
            // Get accounts
            IList<Account> accounts = bankingService.GetAccounts(authToken);
            // Search transactions
            IList<Transaction> transactions = bankingService.GetTransactions(authToken,
                                                                             TimeSpan.FromDays(30), 0, 10);
            // Submit a transfer
            bankingService.Transfer(authToken, new Transaction
                                                   {
                                                       Amount = Decimal.Parse("222.33"),
                                                       Date = DateTime.UtcNow,
                                                       FromAccount = accounts[0],
                                                       ToAccount = accounts[1]
                                                   });
        }
    }
}